<?php
Class JPage  {
		
		var $page      = 0;
		var $pageSize  = 0;
		var $pageStart = 0;

		//ตั้งค่าเลขหน้า
		function set_page($page,$pageSize) {
			empty($page) ? $this->page = 0 : $this->page = ($page-1);
			$this->pageSize  = $pageSize;
			$this->pageStart = ($this->page * $pageSize);
		}
		//
		function get_page($strSql,$url) {
			$link = "";
			$query = query($strSql);
			$pageAll = ceil(num_rows($query)/$this->pageSize);


				for($i=0;$i<$pageAll;$i++) {
				 if ( $i == $this->page )
					$link .= ($i+1)." | ";
				else
					$link .= "<a href=\"".$url."&page=".($i+1)."\">".($i+1)."</a> | ";
				}

			echo $this->_trim($link);
		}

		function post_page($strSql,$frm,$url) {
			$link = "";
			$query = query($strSql);
			$pageAll = ceil(num_rows($query)/$this->pageSize);


				for($i=0;$i<$pageAll;$i++) {
				 if ( $i == $this->page )
					$link .= ($i+1)." | ";
				else
					$link .= "<a href=\"javascript:page_db(".($i+1).",'$frm','$url')\">".($i+1)."</a> | ";
				}

			echo $this->_trim($link);
		}

	
		function _trim($strSql) {
			$strSql = trim($strSql);
			return substr($strSql,0, (strlen($strSql)-1) );
		}
}
?>